Skip to content

Fix HtmlToolTip disposal and the Win32 P/Invoke signatures - #246

Open
kushanp wants to merge 3 commits into
ArthurHub:masterfrom
kushanp:pr/net10-modernization
Open

kushanp wants to merge 3 commits into
ArthurHub:masterfrom
kushanp:pr/net10-modernization

Conversation

@kushanp

@kushanp kushanp commented Jul 25, 2026 •

Copy link
Copy Markdown

Description

Fixes a few things in the WinForms adapter, taken from the original version of this PR, see the comment below for what happened to the rest of it.

  • HtmlToolTip didn't remove its LinkClicked handler on dispose, as that only ran after the container was already set to null, and the timer's Tick handler was never removed
  • The P/Invoke signatures of SetCursor, LoadCursor, GetEnhMetaFileBits and DeleteEnhMetaFile passed handles and the cursor name pointer as int, which isn't pointer sized on x64. They use IntPtr now and uint where the API takes a UINT. Note that MetafileExtensions.GetEnhMetaFileBits and DeleteEnhMetaFile are public, as such their signatures change too
  • HtmlToolTip threw when shown for a window that isn't a control, as it needs the control to measure the HTML, the tooltip is canceled in that case now

How to test this PR?

CI should succeed. Additionally, hover a link in the WinForms demo's HtmlPanel and HtmlLabel, the cursor should still be the system's hand cursor.

Original description

Summary

Modernizes HtmlRenderer.Core and HtmlRenderer.WinForms for .NET 10, with related safety and API fixes.

Targeting

  • Core: net10.0 (was netstandard2.0;net8.0)
  • WinForms: net10.0-windows with UseWindowsForms + Nullable
  • Package bump: System.Resources.Extensions → 10.0.10

Bug / safety fixes

  • 64-bit-safe P/Invoke for Metafile EMF save and cursor handles (IntPtr instead of truncated int)
  • Thread-safe ImageDownloader client list + dedicated lock in ImageLoadHandler
  • HtmlToolTip dispose unsubscription order + null/handle guards
  • Nullable annotations on key public APIs (SetHtml, selection getters, entity Equals)
  • Modern WinForms designer Editor attribute assembly names for .NET 10

Breaking change

This drops multi-targeting for Core (netstandard2.0 / net8.0). Consumers on older TFMs need to multi-target or stay on a previous release. Happy to adjust to multi-target (net8.0 + net10.0) if preferred.

Scope

Only Core + WinForms (no WPF / PdfSharp / Demo changes).

Test plan

  • dotnet build -c Release HtmlRenderer.csproj (net10.0)
  • dotnet build -c Release HtmlRenderer.WinForms.csproj (net10.0-windows)
  • Load assemblies and instantiate HtmlPanel / HtmlContainer.SetHtml(null)

Notes

Rebased onto current master (includes upstream dependency + GHA updates).
A follow-up PR will add HtmlPanel zoom/pan as a separate feature.

@eXpl0it3r
eXpl0it3r force-pushed the pr/net10-modernization branch from 981bb4c to e93e8e4 Compare November 23, 2026 12:06
@eXpl0it3r eXpl0it3r changed the title Target .NET 10 for HtmlRenderer.Core and HtmlRenderer.WinForms Fix HtmlToolTip disposal and the Win32 P/Invoke signatures Nov 23, 2026
@eXpl0it3r

Copy link
Copy Markdown
Collaborator

Thanks for the PR and sorry for the long silence!

.NET 8 and .NET 9 reached their end of support in the mean time, so I've opened #296, which moves all .NET targets to .NET 10. That's the basis for the targeting part of this PR, with one difference: it keeps netstandard2.0 and net462 as they are, since dropping them would cut off every .NET Framework user, and I'd like 2.0 to still cover them.

As such I've replaced the commits here with the fixes that still apply on master, you're kept as the author:

  • The HtmlToolTip dispose order, LinkClicked and the timer's Tick are removed now
  • The P/Invoke signatures, plus lpCursorName of LoadCursor, which is a pointer as well and was still an int
  • The check for a missing AssociatedControl, which cancels the tooltip instead of showing it without content

What I've left out:

  • The retargeting and dropping of netstandard2.0/net8.0, covered by Target .NET 10 instead of .NET 8 #296
  • The Editor attributes, System.Windows.Forms.Design, Version=10.0.0.0 doesn't exist for the net462 build
  • The nullable annotations, they'd be better as one consistent pass over the whole API, instead of a few members
  • The ImageDownloader changes, the class doesn't exist anymore on master
  • The using (CreateGraphics()) and ArgChecker changes, as they don't change any behavior

Let me know if I missed something you'd still like to see in, happy to review a follow-up PR. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants